<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="财务统计">

    <!--suppress ALL -->
    <form id="searchForm" class="form-panel" action="${basepath}/rest/manage/contract/selectContractCountPage" method="get">
        <ul class="panel-content">
            <li>
                <div style="float: left">
                    <label >开始时间：</label>
                        <input name="startDate" class="input-small calendar" type="text" style="width: 100px;"><label>
                        &nbsp;&nbsp;结束时间：</label>
                        <input name="endDate" class="input-small calendar" type="text" style="width: 100px;">&nbsp;&nbsp;

                    <button type="submit" class="button  button-primary" onclick="queryMoney()">
                        查询
                    </button>

                </div>
                <div class="total-money">
                    合同总金额：<span class="moneySum"></span>
                </div>
                <div class="total-money">
                    已支付总金额：<span class="getMoney"></span>
                </div>
                <div class="total-money">
                    待支付总金额：<span class="payMoney"></span>
                </div>
            </li>
        </ul>
    </form>
    <div id="grid"></div>
<script>
    var Calendar = BUI.Calendar
    var datepicker = new Calendar.DatePicker({
        trigger:'.calendar',
        autoRender : true
    });
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title : '序号',elCls: 'center',
                    dataIndex: 'id',
                    dataIndex: 'id',
                    width: '10%',
                    renderer: function (value, obj, index) {
                        return index + 1;
                    }
                },
                {title : '客户名称', dataIndex: 'customerName', elCls: 'center', width: '18%'},
                {title : '总签订合同次数', dataIndex: 'contractAmount', elCls: 'center', width: '18%', renderer: function (value,obj) {
                        return '<a href="${basepath}/rest/manage/finance/toContractCountList?customerID=' + obj.customerID + '">'+value+'</a>';
                    }
                    },


                {title : '合同金额',dataIndex :'contractMoney',elCls: 'center', width: '18%'},
                {title : '已支付金额',dataIndex :'contractGetMoney', elCls: 'center', width: '18%'},
                {title : '待支付金额',dataIndex :'id', elCls: 'center', width: '18%', renderer: function (value,obj) {
                        return obj.contractMoney-obj.contractGetMoney;
                    }
                }


            ];

    var store = new Store({
                url : '/rest/manage/contract/selectContractCountPage',
                autoLoad:true, //自动加载数据
                params : { //配置初始请求的参数
                    length : '10',
                    status:$("#status").val()
                },
                pageSize:10,	// 配置分页数目
                root : 'list',
                totalProperty : 'total'
            }),
            grid = new Grid.Grid({
                render:'#grid',
                columns : columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar:{
                    pagingBar:true
                }
            });

    grid.render();
    //查询金额
    function queryMoney(){
        $.ajax({
            type:'GET',
            dataType:'json',
            url:'/rest/manage/contract/selectAllList',
            data:{
                startDate:$("input[name='startDate']").val(),
                endDate:$("input[name='endDate']").val()
            },
            success:function(data){
                var list=data.data,contractMoney=0,contractGetMoney=0;
                for(var i=0;i<list.length;i++){
                    contractMoney+=list[i].contractMoney;
                    contractGetMoney+=list[i].contractGetMoney;
                }
                $(".moneySum").text(contractMoney);
                $(".payMoney").text(contractMoney-contractGetMoney);
                $(".getMoney").text(contractGetMoney);
            }
        })
    }
    queryMoney();
    /**********************模糊搜索*************************/
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
</script>

</@page.pageBase>
